package com.littlebee.storysuper.utils;

import android.app.Activity;
import android.text.TextUtils;

import com.littlebee.storysuper.BaseApplication;
import com.littlebee.storysuper.entry.User;
import com.zss.library.utils.SharedPrefUtils;

/**
 * Created by zm on 2017/2/28.
 */

public class Utils {

    public static void commonError(Activity activity, String result, String code, String msg){
        if(TextUtils.isEmpty(code) && TextUtils.isEmpty(msg)){
            CommonToastUtils.showInCenterToast(activity, "连接超时");
        }else{
            CommonToastUtils.showInCenterToast(activity, msg+"("+code+")");
        }
    }
    public static boolean isLogin() {
        return getUserEntry() != null;
    }
    public static User getUserEntry() {
        SharedPrefUtils prefUtils = getSharedPrefCommonFile();
        Object obj = prefUtils.get("user");
        if (obj != null) {
            return (User) obj;
        } else {
            return null;
        }
    }
    public static SharedPrefUtils getSharedPrefCommonFile() {
        return new SharedPrefUtils(BaseApplication.getInstance(), "common_file");
    }

    public static void saveUserEntry(User user) {
        SharedPrefUtils prefUtils = getSharedPrefCommonFile();
        prefUtils.put("user", user);
    }



}
